import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/7 15:04
 * @description 排序 但从后往前遍历，枚举C,
 */
public class Solution3 {
    public static void main(String[] args) {

    }

    public int triangleNumber(int[] nums) {
        int count = 0;
        Arrays.sort(nums);
        for (int i = nums.length - 1; i >= 2; i--) {
            int left = 0, right = i - 1;
            while (left < right) {
                if (nums[left] + nums[right] > nums[i]) {
                    count += (right - left);
                    right--;
                } else {
                    left++;
                }
            }
        }
        return count;
    }
}
